package org.example.routing;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class RoutingLogProducerTest {


    public static final String PUB_EXCHANGE = "routing_logs";

    public static void main(String[] args) throws Exception {

        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        try (Connection connection = factory.newConnection();
             Channel channel = connection.createChannel()) {
            //声明广播类型的交换机
            channel.exchangeDeclare(PUB_EXCHANGE, BuiltinExchangeType.DIRECT);
            for (int i = 0; i < 100; i++) {
                //声明一个交换机
                if (i % 3 == 0) {
                    channel.basicPublish(PUB_EXCHANGE, "error", null, ("消息" + i).getBytes());
                } else if (i % 3 == 1) {
                    channel.basicPublish(PUB_EXCHANGE, "info", null, ("消息" + i).getBytes());
                } else {
                    channel.basicPublish(PUB_EXCHANGE, "warn", null, ("消息" + i).getBytes());
                }
                // In the Java client, when we supply no parameters to queueDeclare() we
                // create a non-durable, exclusive, autodelete queue with a generated name:
                // AMQP.Queue.DeclareOk declareOk = channel.queueDeclare();
                // 获取一个非持久化，排他，自动删除的队列
                // String queueName = declareOk.getQueue();
                // channel.queueBind(queueName,PUB_EXCHANGE,"");
            }
        }
    }
}
